using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using PPI.Entities.Interface;
using PPI.Mobile;
using VMind.Global;

namespace PPI.ServiceLogic.Distribution
{
    public class LNote : IMobileTable
    {
        public static DataSet SelectAllIdName(string connectionKey)
        {
            return PPI.Data.Inspection.DInspectionNote.SelectAllIdName(connectionKey);
        }

        public List<EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            DataTable notes = PPI.Data.Inspection.DInspectionNote.SelectAllIdName(connectionKey).Tables[0];

            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            EMobileQuery query = new EMobileQuery(string.Format("DELETE tb_Lookups where LookupTypeFk = '{0}'", "InspectionResult"));
            listQueries.Add(query);

            query = new EMobileQuery("INSERT INTO tb_Lookups (LookupValue,LookupText,LookupTypeFk) values(@id, @Name, 'InspectionResult')");

            foreach (DataRow note in notes.Rows)
            {
                List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(DBHelper.CreateIntParameter("@id", ParameterDirection.Input, false, Convert.ToInt32(note["Vendor_InspVisit_XmissionStructures_NoteId"])));
                parameters.Add(DBHelper.CreateNVarCharParameter("@Name", 100, ParameterDirection.Input, false, note["Name"]));

                query.Parameters.Add(parameters);
            }

            listQueries.Add(query);

            return listQueries;
        }
    }
}